home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / dld-3_23.lha / dld-3.2.3 / defs.h < prev    next >
C/C++ Source or Header  |  1991-05-30  |  6KB  |  205 lines

  1. /* defs.h -- global definitions. */
  2.  
  3. /* This file is part of DLD, a dynamic link/unlink editor for C.
  4.    
  5.    Copyright (C) 1990 by W. Wilson Ho.
  6.  
  7.    The author can be reached electronically by how@ivy.ucdavis.edu or
  8.    through physical mail at:
  9.  
  10.    W. Wilson Ho
  11.    Division of Computer Science
  12.    University of California at Davis
  13.    Davis, CA 95616
  14.  */
  15.  
  16. /* This program is free software; you can redistribute it and/or modify it
  17.    under the terms of the GNU General Public License as published by the
  18.    Free Software Foundation; either version 1, or (at your option) any
  19.    later version. */
  20.  
  21.  
  22. #include <a.out.h>
  23. #include <ar.h>
  24. #include <stdio.h>
  25. #include <sys/types.h>
  26. #include <strings.h>
  27. #include <sys/stat.h>
  28. #include <sys/file.h>
  29. #include <sys/param.h>
  30. #include <setjmp.h>
  31. #include "dld.h"
  32.  
  33. /* Each input file, and each library member ("subfile") being loaded,
  34.    has a `file_entry' structure for it.
  35.  
  36.    For files specified by command args, these are contained in the vector
  37.    which `file_table' points to.
  38.  
  39.    For library members, they are dynamically allocated,
  40.    and chained through the `chain' field.
  41.    The chain is found in the `subfiles' field of the `file_entry'.
  42.    The `file_entry' objects for the members have `superfile' fields pointing
  43.    to the one for the library.  */
  44.  
  45. struct file_entry {
  46.     /* Name of this file.  */
  47.     char *filename;
  48.     /* Name to use for the symbol giving address of text start */
  49.     /* Usually the same as filename, but for a file spec'd with -l
  50.        this is the -l switch itself rather than the filename.  */
  51.     char *local_sym_name;
  52.  
  53.     /* For library member, points to next entry for next member.
  54.        For object or library *file*, points to previously loaded entry */
  55.     struct file_entry *chain;
  56.  
  57.     /* number of undefined symbols referenced by this module */
  58.     int undefined_symbol_count;
  59.   
  60.     /* chain of file_entry that defines symbols this file references */
  61.     struct file_chain *refs;
  62.  
  63.     /* chain of file_entry that references symbols defined in this file */
  64.     struct file_chain *refs_by;
  65.   
  66.     /* reference count -- number of entries referenceing myself */
  67.     int ref_count;
  68.     
  69.     /* Describe the layout of the contents of the file */
  70.  
  71.     /* The file's a.out header.  */
  72.     struct exec header;
  73.  
  74.     /* Describe data from the file loaded into core */
  75.  
  76.     /* Symbol table of the file.  */
  77.     struct nlist *symbols;
  78.     /* Size in bytes of string table.  */
  79.     int string_size;
  80.     /* Pointer to the string table.
  81.        The string table is not kept in core all the time,
  82.        but when it is in core, its address is here.  */
  83.     char *strings;
  84.  
  85.     /* Relocation information of the file. */
  86.  
  87.     /* Start of this file's text relocation information. */
  88.     struct dld_reloc_info *text_reloc;
  89.     /* Start of this file's data relocation information. */
  90.     struct dld_reloc_info *data_reloc;
  91.     
  92.     /* Relation of this file's segments to the output buffer */
  93.  
  94.     /* Start of this file's text seg in the output file core image.  */
  95.     int text_start_address;
  96.     /* Start of this file's data seg in the output file core image.  */
  97.     int data_start_address;
  98.     /* Start of this file's bss seg in the output file core image.  */
  99.     int bss_start_address;
  100.  
  101.     /* For library members only */
  102.  
  103.     /* For a library, points to chain of entries for the library members.  */
  104.     struct file_entry *subfiles;
  105.     /* For a library member, offset of the member within the archive.
  106.        Zero for files that are not library members.  */
  107.     int starting_offset;
  108.     /* Size of contents of this file, if library member.  */
  109.     int total_size;
  110.     /* For library member, points to the library's own entry.  */
  111.     struct file_entry *superfile;
  112.  
  113.     /* 1 if file is a library. */
  114.     char library_flag;
  115.  
  116.     /* 1 if file's header has been read into this structure.  */
  117.     char header_read_flag;
  118.  
  119.     /* 1 if this module has all external references resolved */
  120.     char all_symbols_resolved_flag;
  121.   
  122.     /* 1 if functions in this module can be safely executed. */
  123.     char executable_flag;
  124.  
  125.     /* 1 if this module has already been (soft) unlinked. */
  126.     char already_unlink;
  127.     /* 1 means search a set of directories for this file.  */
  128.     /* char search_dirs_flag; */
  129. };
  130.  
  131.  
  132. /* format of file_entry chain */
  133. struct file_chain {
  134.     struct file_chain *next;
  135.     struct file_entry *entry;
  136. };
  137.  
  138. /* Symbol table */
  139.  
  140. /* Global symbol data is recorded in these structures,
  141.    one for each global symbol.
  142.    They are found via hashing in 'symtab', which points to a vector of buckets.
  143.    Each bucket is a chain of these structures through the link field.  */
  144.  
  145. typedef
  146.   struct glosym
  147.     {
  148.       /* Pointer to next symbol in this symbol's hash bucket.  */
  149.       struct glosym *link;
  150.       /* Name of this symbol.  */
  151.       char *name;
  152.       /* Value of this symbol as a global symbol.  */
  153.       long value;
  154.       /* Points to the file_entry that defines this symbol */
  155.       struct file_entry *defined_by;
  156.       /* chain of file_entry that contains reference to this symbol */
  157.       struct file_chain *referenced_by;
  158.       /* Nonzero means a definition of this global symbol is known to exist.
  159.      Library members should not be loaded on its account.  */
  160.       char defined;
  161.       /* Nonzero means a reference to this global symbol has been seen
  162.      in a file that is surely being loaded. */
  163.       char referenced;
  164.     }
  165.   symbol;
  166.  
  167. /* Number of buckets in symbol hash table */
  168. #define    TABSIZE    1009
  169.  
  170. /* this is commonly used in removing single linked-list elements. */
  171. #define del_link_list_elt(head, prev, current, next) { \
  172.     if (prev == 0) { \
  173.     head = current->next; \
  174.     free (current); \
  175.     current = head; \
  176.     } else { \
  177.     prev->next = current->next; \
  178.     free (current); \
  179.     current = prev->next; \
  180.     } }
  181.  
  182. /* The symbol hash table: a vector of TABSIZE pointers to struct glosym. */
  183. extern symbol *_dld_symtab[TABSIZE];
  184.  
  185. /* variable for saving the environment */
  186. extern jmp_buf _dld_env;
  187.  
  188. /* pointer to the lastest (newest) file entry */
  189. extern struct file_entry *_dld_latest_entry;
  190.  
  191. /* dummy file_entry to hold all "dangling" symbols. */
  192. extern struct file_entry *_dld_dummy_entry;
  193.  
  194. /* true if the executable flags are up-to-date */
  195. extern char _dld_exec_flags_valid;
  196.  
  197. extern int _dld_malloc ();
  198. extern symbol *_dld_getsym ();
  199. extern symbol *_dld_getsym_soft ();
  200. extern void _dld_enter_global_ref ();
  201. extern void _dld_unlink_entry ();
  202. extern void _dld_create_dummy_entry ();
  203. extern void _dld_patch_all_files ();
  204.  
  205.